<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
<meta http-equiv="Pragma" content="no-cache" >
<meta http-equiv="Cache-Control" content="no-cache" >
<meta http-equiv="Expires" content="-1" >

<link rel="shortcut icon" href="/icon/info.niwota.install">
<title>APK Install</title>

<link rel="stylesheet" href="/assets/style/common.css" type="text/css">

<style type="text/css">

ul {
	list-style: disc inside;
	margin-left: 1em;
}

#content {
	padding: 10px;
}

label {
	float: left;
	width: 12em;
}

input[type=text] { width: 15em; }

</style>

<script type="text/javascript" src="/assets/opt/script/jquery.js"></script>
<script type="text/javascript" src="/assets/script/common.js"></script>
<script type='text/javascript' src="/content/info.niwota.install/assets/opt/script/jquery.form.js"></script>

<script type="text/javascript">
var spinner = '<img src="/assets/image/spin.gif" alt="Please wait..." ><span style="color: white; font-size: xx-large;">...<blink>.....</blink></span>';
//var jsonp = '/content/info.niwota.install/jsonp/installer/install?type=json&callback=?';
var jsonp = '/content/info.niwota.install/jsonp/installer/install';

$.ajaxSetup ({  
	cache: false  
}); 

$(document).ready(function(){
	$.initOptionMenu();
	//
	initForm();
});

function showBusy(timeout, msg) {
	var tag = $('#status');
	
	var t = timeout || 3000;
	var m = msg || '';
	tag.html(spinner);
	var timer = setTimeout(function(){ tag.html(m).css({ "color": "#ff0000" }); }, t);
	
	this.cancel = function() {
		clearTimeout(timer);
		tag.empty();
	}
	
	return this;
}

var busy = null;

function initForm() {
   var options = { 
        target: '#status',   // target element(s) to be updated with server response 
        beforeSubmit:  preSubmit,  // pre-submit callback 
        success: postSubmit,  // post-submit callback 
 
        // other available options: 
        //url:       url,         // override for form's 'action' attribute 
        //type:      type,        // 'get' or 'post', override for form's 'method' attribute 
        dataType:  'json',       // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: false,        // clear all form fields after successful submit 
        //resetForm: false,        // reset the form after successful submit 
 		//forceSync: true,
        // $.ajax options can be used here too, for example: 
        timeout:   300000 
    }; 
 	
 	// bind form 
    //$('#uploadform').ajaxForm(options);
    
    $('#uploadform').submit(function(e) { 
        $(this).ajaxSubmit(options); 
        return false; 
    });
}

function preSubmit(formData, jqForm, options) {
	var err = $('#status');

	err.text(''); 
	busy = showBusy(300000, 'Timeout, please try again.');
	
	return true;
}

function postSubmit(d, statusText, xhr, form) {
	if (busy) {
		busy.cancel();
	}
	var tag = $('#status');
	if (d && d.rc == false) {
		tag.html(d.error).css({ "color": "#ff0000" });
	} else {
		tag.html('Success!').css({ "color": "#00ff00" });
	}
}

function parseData(d) {
	var parsed = [];
	if (d && d.length > 1) {
		var sa = d[1];
		for (var i = 0; i < sa.length; i++) {
			var w = $.trim(sa[i][0]);
			if (w) {
				w = w.split("|");
				parsed[parsed.length] = {
					data: w,
					value: w[0],
					result: w[0]
				};
			}
		}
	}
	return parsed;
}
</script>
</head>
<body>

<div id="topnav">
	<a class="logo" href="/content/info.niwota.install" title="Install from a browser">
	<img class="icon32" src="/icon/info.niwota.install"  alt="" >
	<span>APK Install</span>
	</a>

	<span class="top-center"></span>
	
	<span class="top-right" style="margin-right: 64px;">

	<span class="action"><a class="" target="help" href="/content/info.niwota.install/assets/web/help.htm" >Help</a></span>&nbsp;|&nbsp;
	<span class="action"><a href="#" onclick="self.close();">Quit</a></span>
	
	</span>
</div>

<!--page content-->
<div id="page-content">

<div style="clear: both;"></div>

<div id="content" style="z-index: 1000;">
	<form name="uploadform" id="uploadform" autocomplete="off"
	action="/content/info.niwota.install/jsonp/installer/install"  
	method="post" enctype="multipart/form-data"
	>
	<p>
	<!--
	<input type="checkbox" id="remove" name="remove" value="true" checked="checked" />
	<span style="color: #0ff;">Remove previous version</span>
	-->
	</p>
	<p>
	<input type="file" size="32" name="apk" style="color: #000; background-color: #fff"/> <br />
	<input type="submit" value="Install" name="submit1" id="submit1" />
	</p>
	</form> 
	<p><span id="status" style="color: #f00;"></span></p>
</div>

</div>
<!--//page content-->

<div id="optionmenu">
<a class="" target="help" href="/content/info.niwota.install/assets/web/help.htm" title="Help" ><img src="/res/drawable/ic_menu_help" /></a>
<a href="#" title="Quit" onclick="self.close();"><img src="/res/drawable/ic_menu_done" /></a>
</div>

<div id="footer">

<span style="color: #fff;">APK Install 1.0.0 &copy; 2010 All rights reserved</span> 

</div>

<div id="wallpaper" style="display: block;"><img src="/wallpaper" width="100%" height="100%" /></div>

</body>
</html>